package com.mingtu.jgspatrol.adapter;

import android.content.Context;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.mingtu.jgspatrol.R;
import com.mingtu.jgspatrol.bean.TaskTrackBean;

import java.util.ArrayList;
import java.util.List;

public class Task1Adapter extends BaseQuickAdapter<TaskTrackBean.PageBean.ListBean, BaseViewHolder> {
    private Context context;
    private List<TaskTrackBean.PageBean.ListBean> mData = new ArrayList<>();
    private OnItemClickListener mOnItemClickListener = null;

    public Task1Adapter() {
        super(R.layout.item_task);
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, TaskTrackBean.PageBean.ListBean listBean) {
        String taskNo = listBean.getTaskNo();
        String beginTime = listBean.getBeginTime();
        String endTime = listBean.getEndTime();
        String rate = listBean.getRate();
        double myRate = 0;
        if (!StringUtils.isEmpty(rate)) {
            myRate = Double.parseDouble(rate);
        }

        if (!StringUtils.isEmpty(taskNo)) {
            helper.setText(R.id.tv_task_name, "编号：" + taskNo);
        }

        if (!StringUtils.isEmpty(beginTime)) {
            helper.setText(R.id.tv_create_time, "开始时间：" + beginTime);
        }

        if (!StringUtils.isEmpty(endTime)) {
            helper.setText(R.id.tv_end_time, "截止时间：" + endTime);
        }


        helper.setText(R.id.tv_task_type, "任务类型：巡护任务");
        helper.setGone(R.id.tv_complete_rate, true);
        if (myRate == 0) {
            setCompleteRate(helper, "完成率：" + myRate + "%", R.color.red_fc);
        } else if (myRate > 0 && myRate < 100) {
            setCompleteRate(helper, "完成率：" + myRate + "%", R.color.colorPrimary);
        } else if (myRate == 100) {
            setCompleteRate(helper, "已完成", R.color.text_color999);
        }

    }

    private void setCompleteRate(BaseViewHolder helper, String s, int color) {
        TextView tvCompleteRate = helper.getView(R.id.tv_complete_rate);
        tvCompleteRate.setText(s);
        tvCompleteRate.setTextColor(context.getResources().getColor(color));
    }

}
